﻿Public Class CWordDetail
    Dim _ID As String
    
    Public Property ID() As String
        Set(ByVal value As String)
            _ID = value
        End Set
        Get
            Return _ID
        End Get
    End Property

    Public Sub LoadData()
        Dim rs As ADODB.Recordset = ct.GetTable("select * from XSCENLISHWORD where ID='" + _datagridview.SelectedRows(0).Cells("id").Value.ToString() + "'")
        If rs Is Nothing Then Exit Sub
        If rs.EOF = False Then
            Me.lstEnglistWord.Text = CStr(rs.Fields("WORD").Value)
            Me.lstChinaWord.Text = CStr(rs.Fields("CHINESEWORD").Value)
            Me.lstJuzi.Text = CStr(rs.Fields("MEMO").Value)
            rs.Close()
            System.Runtime.InteropServices.Marshal.ReleaseComObject(rs) '20100531
            rs = Nothing
        End If

        MyLabel3.Text = (_datagridview.SelectedRows(0).Index + 1).ToString() + "/" + _datagridview.RowCount.ToString()
    End Sub

    Private Sub CWordDetail_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If _datagridview.Rows.Count > 0 Then
            If _datagridview.SelectedRows.Count = 0 Then
                _datagridview.Rows(0).Selected = True
            End If
        End If

        LoadData()
    End Sub

    Public _datagridview As DataGridView
    Public Sub New(ByVal dv As DataGridView)

        ' 此调用是 Windows 窗体设计器所必需的。
        InitializeComponent()

        ' 在 InitializeComponent() 调用之后添加任何初始化。
        _datagridview = dv
    End Sub

    Private Sub btnFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFirst.Click
        If _datagridview.Rows.Count > 0 Then
            _datagridview.Rows(0).Selected = True
            _datagridview.FirstDisplayedScrollingRowIndex = _datagridview.SelectedRows(0).Index
            LoadData()
        End If
    End Sub

    Private Sub btnPre_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPre.Click
        If _datagridview.Rows.Count > 0 Then
            If _datagridview.SelectedRows.Count = 0 Then
                _datagridview.Rows(0).Selected = True
            Else
                If _datagridview.SelectedRows(0).Index > 0 Then
                    _datagridview.Rows(_datagridview.SelectedRows(0).Index - 1).Selected = True
                    _datagridview.FirstDisplayedScrollingRowIndex = _datagridview.SelectedRows(0).Index
                End If
            End If

            LoadData()
        End If
    End Sub

    Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
        If _datagridview.Rows.Count > 0 Then
            If _datagridview.Rows.Count > 0 Then
                If _datagridview.SelectedRows.Count = 0 Then
                    _datagridview.Rows(0).Selected = True
                Else
                    If _datagridview.SelectedRows(0).Index < _datagridview.RowCount - 1 Then
                        _datagridview.Rows(_datagridview.SelectedRows(0).Index + 1).Selected = True
                        _datagridview.FirstDisplayedScrollingRowIndex = _datagridview.SelectedRows(0).Index
                    End If
                End If

                LoadData()
            End If
        End If
    End Sub

    Private Sub btnLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLast.Click
        If _datagridview.Rows.Count > 0 Then
            _datagridview.Rows(Me._datagridview.RowCount - 1).Selected = True
            _datagridview.FirstDisplayedScrollingRowIndex = _datagridview.SelectedRows(0).Index
            LoadData()
        End If
    End Sub
End Class
